#include <glib/g2/types.h>
#include <glib/g2/arc.h>
#include <glib/g2/polyline.h>
#include <math/pi.h>

namespace g2 {

arc::arc(const vector & center, double radius, double start, double end) : 
	_center(center), _radius(radius),
	_start(start), _end(end)
{
}

polyline arc::flatten(double h) const
{
	if (_radius == 0)
		return polyline(std::vector<vector>(1, _center));
	size_type count = size_type(fabs(_end - _start) * _radius / h);
	polyline p((std::vector<vector>(count + 1)));
	p[0] = _center + vector(cos(_start), sin(_start)) * _radius;
	for (size_type i = 1; i <= count; ++i) {
		double a = _start + i * (_end - _start) / count;
		p[i] = _center + vector(cos(a), sin(a)) * _radius;
	}
	return p;
}

vector arc::center() const
{
	return _center;
}

box arc::bounds() const
{
	return box(_center).inflate(_radius, _radius);
}

void arc::translate(const vector & t)
{
	_center += t;
}

void arc::rotate(const vector & center, double angle)
{
	// 
	assert(false);
}

} // g2
